<!DOCTYPE html>
<html>
<head>

<!-- Cria uma masca no input texto -->
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/mascara.js" type="text/javascript"></script> 

<!--Exibe um calendário na data para escolha -->
<link rel="stylesheet" href="estilos/jquery-ui.css" />
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui-1.10.4.custom.js"></script>
<script src="js/dataPicker.js"></script>

<meta charset='iso-8859-1'>
	
	<title></title>
	<?php
		session_start();
		include_once '../gerenciadores/AutoloadGerenciadores.php';
		include_once 'function/LocalizaRequisicao.php';
		include_once 'function/data.php';
		
		
		if(isset($_POST['btn_confirma']) && $_POST['btn_confirma']=="Confirma"){
			if(isset($_POST['id'])){
				$tabId = $_POST['id'];
				$tabControle = $_POST['controle'];
				$tabLiberacao = $_POST['liberacao'];


				$tabRequisicao = unserialize($_SESSION['tabRequisicao']);

				if(!isset($gerSmap)){
					__autoload("GerenciadorDaSmap");
					$gerSmap = new GerenciadorDaSmap();
				}

				foreach ($tabId as $linha){
					$requisicao = localizaRequisicao($linha, $tabRequisicao);
					$requisicao->setControle($tabControle[$linha]);
					$requisicao->setLiberacao($tabLiberacao[$linha]);
					$gerSmap->alteraRequisicao($requisicao);
				}
			}	
		}
		if(isset($_POST['btn_confirma']) && $_POST['btn_confirma']=="Exclui"){
			$tabId = $_POST['id'];
			$tabRequisicao = unserialize($_SESSION['tabRequisicao']);

			if(!isset($gerSmap)){
				__autoload("GerenciadorDaSmap");
				$gerSmap = new GerenciadorDaSmap();
			}
			
			foreach ($tabId as $linha){
				$requisicao = localizaRequisicao($linha, $tabRequisicao);
				$gerSmap->deletaRequisicao($requisicao); 
				
			}
		}
		
	?>
	
</head>
<body>
<form name="data_requisicao" method="post" action="#">
	<label>Data: </label><input type="text" name="data" class="data" onkeypress="formatar_mascara(this,'##/##/####')">
	<input type="submit" value="Visualiza">
</form>
<table>
	<form name="requisicao" method="POST" action="#">
	<tr>
		<th>Sel</th><th>Material</th><th>Quantidade</th><th>Hor�rio</th><th>Instrutor</th><th>Turma</th><th>Controle</th><th>Libera��o</th>
	</tr>
		<?php
	 		
			if(isset($_POST['data'])){
				
				
				if(!isset($gerSmap)){
					__autoload("GerenciadorDaSmap");
					$gerSmap = new GerenciadorDaSmap();
				}
				
				
				$data = $_POST['data'];
				$tabela = $gerSmap->exibeRequisicaoPorData(converteData($data));
				$_SESSION['tabRequisicao'] = serialize($tabela);
				
				foreach ($tabela as $linha){
					echo "<tr>";
					echo "<td><input type='checkbox' value='".$linha->getIdRequisicao()."' name='id[]'></td>";
					echo "<td>".$linha->getMaterial()->getDescricao()."</td>";
					echo "<td>".$linha->getMaterial()->getQuantidade()."</td>";
					echo "<td>";
					switch ($linha->getTurno()){
						case 11:echo "Manh� - 1� Hor�rio";
						break;
						case 12:echo "Manh� - 2� Hor�rio";
						break;
						case 21:echo "Tarde - 1� Hor�rio";
						break;
						case 22:echo "Tarde - 2� Hor�rio";
						break;
						case 31:echo "Noite - 1� Hor�rio";
						break;
						case 32:echo "Noite - 2� Hor�rio";
						break;
					}
					echo "</td>";
					echo "<td>".$linha->getInstrutor()."</td>";
					echo "<td>".$linha->getTurma()."</td>";
					echo "<td><input type='text' value='".$linha->getControle()."' name='controle[".$linha->getIdRequisicao()."]'></td>";
					if($linha->getLiberacao()==1){
						echo "<td><input type='radio' value='1' name='liberacao[".$linha->getIdRequisicao()."]' checked>Sim
						<input type='radio' value='0' name='liberacao[".$linha->getIdRequisicao()."]'>N�o</td>";
					}else{
						echo "<td><input type='radio' value='1' name='liberacao[".$linha->getIdRequisicao()."]'>Sim
						<input type='radio' value='0' name='liberacao[".$linha->getIdRequisicao()."]' checked>N�o</td>";
					}
					
					echo "</tr>";
					}
			}
	 		
?>
	<tr>
	<td colspan="8">
		<input type="submit" value="Confirma" name="btn_confirma">
		<input type="submit" value="Exclui" name="btn_confirma">
	</td>
	</tr>
	</form>
</table>
</body>
</html>